package common.utils;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SecureUtil
{
	static public String getMD5(String source) throws NoSuchAlgorithmException, UnsupportedEncodingException
	{
		MessageDigest digest = MessageDigest.getInstance("MD5");
		digest.update(source.getBytes("UTF-8"));
		String result = new BigInteger(1, digest.digest()).toString(16);
		return result;
	}

	static public String getSHA1(String source) throws NoSuchAlgorithmException, UnsupportedEncodingException
	{
		MessageDigest digest = MessageDigest.getInstance("SHA1");
		digest.update(source.getBytes("UTF-8"));
		String result = new BigInteger(1, digest.digest()).toString(16);
		return result;
	}
}
